package top.soning.disk.controller.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "cors" , urlPatterns = "/*")
public class CorsFilter implements Filter {
    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException{
        HttpServletResponse response = (HttpServletResponse) res;
        System.out.println("-------- Filter DO --------");
        response.setHeader("Access-Control-Allow-Origin","*");
        response.setHeader("Access-Control-Allow-Method","POST GET DELETE PUT OPTIONS");
        response.setHeader("Access-Control-Allow-Headers","Authorization Content-Type");
        chain.doFilter(req,res);
    }
    @Override
    public void init(FilterConfig filterConfig) {
        System.out.println("-------- Filter Init --------");
    }
    @Override
    public void destroy() {}
}
